namespace Asmex.FileViewer
{
    using Asmex.ObjViewer;
    using System;
    using System.IO;

    public class COR20Header : Region
    {
        private uint _CB;
        private DataDir _CodeManagerTable;
        private uint _EntryPointToken;
        private DataDir _ExportAddressTableJumps;
        private uint _Flags;
        private ushort _MajorRuntimeVersion;
        private DataDir _ManagedNativeHeader;
        private DataDir _MetaData;
        private ushort _MinorRuntimeVersion;
        private DataDir _Resources;
        private DataDir _StrongNameSignature;
        private DataDir _VTableFixups;

        public COR20Header(BinaryReader reader)
        {
            base.Start = reader.BaseStream.Position;
            this._CB = reader.ReadUInt32();
            this._MajorRuntimeVersion = reader.ReadUInt16();
            this._MinorRuntimeVersion = reader.ReadUInt16();
            this._MetaData = new DataDir(reader, "MetaDataDir");
            this._Flags = reader.ReadUInt32();
            this._EntryPointToken = reader.ReadUInt32();
            this._Resources = new DataDir(reader, "ResourcesDir");
            this._StrongNameSignature = new DataDir(reader, "StrongNameSignatureDir");
            this._CodeManagerTable = new DataDir(reader, "CodeManagerTableDir");
            this._VTableFixups = new DataDir(reader, "VTableFixupsDir");
            this._ExportAddressTableJumps = new DataDir(reader, "ExportAddressTableJumpsDir");
            this._ManagedNativeHeader = new DataDir(reader, "ManagedNativeHeaderDir");
            base.Length = reader.BaseStream.Position - base.Start;
        }

        public uint CB
        {
            get
            {
                return this._CB;
            }
        }

        public DataDir CodeManagerTable
        {
            get
            {
                return this._CodeManagerTable;
            }
        }

        [ObjViewer(Hex=true)]
        public uint EntryPointToken
        {
            get
            {
                return this._EntryPointToken;
            }
        }

        public DataDir ExportAddressTableJumps
        {
            get
            {
                return this._ExportAddressTableJumps;
            }
        }

        [ObjViewer(Hex=true)]
        public uint Flags
        {
            get
            {
                return this._Flags;
            }
        }

        public ushort MajorRuntimeVersion
        {
            get
            {
                return this._MajorRuntimeVersion;
            }
        }

        public DataDir ManagedNativeHeader
        {
            get
            {
                return this._ManagedNativeHeader;
            }
        }

        public DataDir MetaData
        {
            get
            {
                return this._MetaData;
            }
        }

        public ushort MinorRuntimeVersion
        {
            get
            {
                return this._MinorRuntimeVersion;
            }
        }

        public DataDir Resources
        {
            get
            {
                return this._Resources;
            }
        }

        public DataDir StrongNameSignature
        {
            get
            {
                return this._StrongNameSignature;
            }
        }

        public DataDir VTableFixups
        {
            get
            {
                return this._VTableFixups;
            }
        }
    }
}
